package com.ml.mall.controller.catalogue;

import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.catalogue.*;
import com.ml.mall.bean.res.product.SysProductShopPageRes;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.service.catalogue.SysCatalogueProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.Valid;
import java.util.List;

import com.ml.mall.service.catalogue.SysCatalogueService;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
*  前端控制器
* </p>
*
* @author pl
* Created 2021-05-25
*/

@Api(tags = "【dim】收藏目录相关接口")
@RestController
@RequestMapping("/catalogue")
public class SysCatalogueController extends BaseController{

     @Autowired
     private SysCatalogueService SysCatalogueService;
     @Autowired
     private SysCatalogueProductService sysCatalogueProductService;

    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @ApiOperation(value="创建新的收藏目录")
//    @RequiresPermissions(PermissionConst.CATALOGUE_NEW)
    public ApiRestResult sysCatalogueNew(@Valid @RequestBody SysCatalogueAddDto dto ) {
        return ApiRestResult.ok(SysCatalogueService.sysCatalogueNew(dto));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/query")
    @ApiOperation("查询收藏夹id以及收藏夹名称")
//    @RequiresPermissions(PermissionConst.CATALOGUE_QUERY)
    public ApiRestResult sysCatalogueQuery() {
        return ApiRestResult.ok(SysCatalogueService.sysCatalogueQuery());
    }

    @RequestMapping(method = RequestMethod.POST, path = "/add_product")
    @ApiOperation(value = "收藏目录添加产品")
//    @RequiresPermissions(PermissionConst.CATALOGUE_ADD_PRODUCT)
    public ApiRestResult sysCatalogueEdit(@Valid @RequestBody SysCatalogueProductAddDto dto ) {
        return ApiRestResult.ok(sysCatalogueProductService.sysCatalogueProductAdd(dto));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/query_all")
    @ApiOperation("查询收藏夹id以及收藏夹名称")
//    @RequiresPermissions(PermissionConst.CATALOGUE_QUERY_ALL)
    public ApiRestResult sysCatalogueProductQueryAll() {
        return ApiRestResult.ok(sysCatalogueProductService.sysCatalogueProductQueryAll());
    }

    @PostMapping("/query_catalogue_product")
    @ApiOperation("收藏夹中产品的全查询")
//    @RequiresPermissions(PermissionConst.CATALOGUE_QUERY_CATALOGUE_PRODUCT)
    public ApiRestResult catalogueProductQueryList(@RequestBody CatalogueDto dto) {
        List<SysProductShopPageRes> catalogueProductResList = sysCatalogueProductService.catalogueProductQueryList(dto);
        return ApiRestResult.ok(catalogueProductResList);
    }

    @PostMapping("/del_catalogue_by_id")
    @ApiOperation("删除收藏夹")
//    @RequiresPermissions(PermissionConst.CATALOGUE_DEL_CATALOGUE_BY_ID)
    public ApiRestResult delCatalogue(@RequestBody CatalogueDelDto dto) {
        return ApiRestResult.ok( SysCatalogueService.delCatalog(dto) );
    }

    @PostMapping("/edit_catalogue_variant")
    @ApiOperation("修改收藏夹中的变体;")
//    @RequiresPermissions(PermissionConst.CATALOGUE_EDIT_CATALOGUE_VARIANT)
    public ApiRestResult editCatalogueVariant(@RequestBody SysCatalogueVariantEditDto dto) {
        return ApiRestResult.ok(sysCatalogueProductService.editCatalogueVariant(dto));
    }


    @PostMapping("/del_variant_from_catalog")
    @ApiOperation("从收藏夹中删除变体")
//    @RequiresPermissions(PermissionConst.CATALOGUE_DEL_VARIANT_FROM_CATALOG)
    public ApiRestResult delCatalogue(@RequestBody CatalogueDelVariantDto dto) {
        return ApiRestResult.ok(sysCatalogueProductService.delVariantFromCatelgogue(dto));
    }

    @PostMapping("/edit")
    @ApiOperation("编辑收藏夹")
//    @RequiresPermissions(PermissionConst.CATALOGUE_EDIT)
    public ApiRestResult editCatalogue(@RequestBody CatalogueEditDto dto){
        return ApiRestResult.ok(sysCatalogueProductService.editCatalogue(dto));
    }

    @PostMapping("/edit_name")
    @ApiOperation("编辑收藏夹名称")
//    @RequiresPermissions(PermissionConst.CATALOGUE_EDIT_NAME)
    public ApiRestResult editCatalogueName(@RequestBody CatalogueNameEditDto dto){
        return ApiRestResult.ok(sysCatalogueProductService.editCatalogueName(dto));
    }
}
